// index.js
// 获取应用实例
const app = getApp()
var api=app.api;
Page({
  data: {
    searchValue:"",
    page_no:1,
    page_size:10,
    articleList:[

    ]
  },
  onPullDownRefresh() {
      console.log("...下拉刷新...")
      this.setData({page_no:1})
      this.setData({
        articleList:[]
     })
      this.getArticleList();
      wx.stopPullDownRefresh()
  },
    /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.log("...到底刷新...")
    let newPageNo=this.data.page_no+1;
    this.setData({page_no:newPageNo})
    this.getArticleList();
  },

  // 事件处理函数
  bindViewTap(event) {
    let id=event.currentTarget.dataset.id;
    console.log("...列表主键id=",id);
    wx.navigateTo({
      url: '../detail/detail?id='+id
    })
  },
  onLoad() {
      this.getArticleList();
  },

  //输入框input绑定事件
  bindSearchInputValue(e){
    this.setData({
      searchValue: e.detail.value
    })
  },
  //失去焦点触发
  bindSearchInputValueConfirm(e){
      console.log("....i am value",this.data.searchValue)
      this.setData({page_no:1})
      this.setData({
        articleList:[]
     })
      this.getArticleList();
  },
  getArticleList(){
    api.GetAllArticleList({"page_no":this.data.page_no,"page_size":this.data.page_size,"search_name":this.data.searchValue},resp=>{
         const{data}=resp;
         const {data_list}=data;
         console.log("文章列表==",data_list)
         let newList=this.data.articleList
         for(var i=0;i<data_list.length;i++){
           newList.push(data_list[i])
         }
         this.setData({
            articleList:newList
         })
    })
  }
})
